home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #27 (Dec 87) / Tear off Menus example / ls Pascal version / TearMenu.main next >
Text File  |  1987-11-19  |  17KB  |  699 lines

  1. PROGRAM TearMenu;
  2.  
  3. { Example of tear-off menus}
  4. { by Daryl Lovato for MacTutor}
  5. { Inspired by HyperCard}
  6.  
  7. {global constants}
  8.     CONST
  9.         AppleMenuID = 1;
  10.         FileMenuID = 2;
  11.         EditMenuID = 3;
  12.         graphicalMenu = 4;
  13.         WindResID = 1;
  14.         AboutID = 3000;
  15.  
  16. {global variables}
  17.     VAR
  18.         myMenus : ARRAY[AppleMenuID..EditMenuID] OF MenuHandle;
  19.         Done : Boolean;
  20.         RegWDEFWindow : WindowPtr;
  21.         GrowArea : rect;
  22.         DragArea : rect;
  23.         myWindowPeek : WindowPeek;
  24.         MyGraphicsMenu : menuhandle;
  25.         currentPatWind : WindowPtr;
  26.  
  27. { My Window Definition Function }
  28.  
  29.     FUNCTION MyWindowDef (varCode : Integer;
  30.                                     theWindow : WindowPtr;
  31.                                     message : Integer;
  32.                                     param : LongInt) : LongInt;
  33.         TYPE
  34.             RectPtr = ^Rect;
  35.  
  36.         VAR
  37.             aRectPtr : RectPtr;
  38.             myWindowPeek : WindowPeek;
  39.  
  40.         PROCEDURE DoDrawMessage (WindToDraw : WindowPtr;
  41.                                         DrawParam : LongInt);
  42.             VAR
  43.                 TitleBarRect : Rect;
  44.                 CurrentY : Integer;
  45.                 index : Integer;
  46.                 GoAwayBox : Rect;
  47.                 Show : boolean;
  48.                 WindowRec : WindowPeek;
  49.         BEGIN
  50.             WindowRec := WindowPeek(WindToDraw);
  51.             Show := WindowRec^.visible;
  52.             IF Show THEN
  53.                 BEGIN
  54.  
  55.                     TitleBarRect := WindowRec^.strucRgn^^.rgnBBox;
  56.  
  57.                     IF DrawParam <> 0 THEN {just toggle goAway box}
  58.                         BEGIN
  59.                             WITH TitleBarRect DO
  60.                                 BEGIN
  61.                                     top := top + 3;
  62.                                     left := left + 5;
  63.                                     bottom := top + 8;
  64.                                     right := left + 8;
  65.                                 END;
  66.                             InsetRect(TitleBarRect, 1, 1);
  67.                             InvertRect(TitleBarRect);
  68.                         END
  69.                     ELSE {we need to draw the window frame}
  70.                         BEGIN
  71.                             PenNormal;
  72.  
  73.                             FrameRect(TitleBarRect);
  74.  
  75.                             TitleBarRect.bottom := TitleBarRect.top + 13;
  76.  
  77.                             FrameRect(TitleBarRect);
  78.                             InsetRect(TitleBarRect, 1, 1); {shrink by 1}
  79.                             EraseRect(TitleBarRect);
  80.  
  81.                             IF WindowRec^.hilited THEN
  82.                                 BEGIN { add hiliting }
  83.                                     FillRect(TitleBarRect, black);
  84.                                     WITH TitleBarRect DO
  85.                                         BEGIN
  86.                                             top := top + 2;
  87.                                             left := left + 4;
  88.                                             bottom := top + 8;
  89.                                             right := left + 8;
  90.                                         END;
  91.                                     PenMode(patXor);
  92.                                     FrameRect(TitleBarRect);
  93.                                     PenNormal;
  94.                                 END;
  95.                         END;
  96.                 END;
  97.         END;
  98.  
  99.         FUNCTION DoHitMessage (WindToTest : WindowPtr;
  100.                                         theParam : LongInt) : LongInt;
  101.             VAR
  102.                 globalPt : Point;
  103.                 aRect : Rect;
  104.                 GoAwayBox : Rect;
  105.                 tempRect : Rect;
  106.                 WindowRec : WindowPeek;
  107.         BEGIN
  108.             globalPt.h := LoWord(theParam);
  109.             globalPt.v := HiWord(theParam);
  110.             WindowRec := WindowPeek(WindToTest);
  111.             aRect := WindowRec^.strucRgn^^.rgnBBox;
  112.             aRect.bottom := aRect.top + 12; {create tBar Rect}
  113.             tempRect := WindowRec^.strucRgn^^.rgnBBox;
  114.             IF PtInRect(globalPt, tempRect) THEN {in structure rgn?}
  115.                 BEGIN
  116.                     tempRect := WindowRec^.contRgn^^.rgnBBox;
  117.                     IF PtInRect(globalPt, tempRect) THEN {if it was in content rgn}
  118.                         DoHitMessage := wInContent
  119.                     ELSE IF PtInRect(globalPt, aRect) THEN {in the drag or go-away}
  120.                         BEGIN
  121.                             IF WindowRec^.hilited THEN
  122.                                 BEGIN {we need to check the go-away box}
  123.                                     WITH aRect DO
  124.                                         BEGIN
  125.                                             top := top + 2;
  126.                                             left := left + 4;
  127.                                             bottom := top + 8;
  128.                                             right := left + 8;
  129.                                         END;
  130.                                     IF PtInRect(globalPt, aRect) THEN
  131.                                         DoHitMessage := wInGoAway
  132.                                     ELSE
  133.                                         DoHitMessage := wInDrag;
  134.                                 END
  135.                             ELSE
  136.                                 DoHitMessage := wInDrag;
  137.                         END
  138.                     ELSE {it was in our window frame}
  139.                         DoHitMessage := wNoHit;
  140.                 END
  141.             ELSE {it wasn't in our window at all}
  142.                 DoHitMessage := wNoHit;
  143.         END;
  144.  
  145.         PROCEDURE DoCalcRgnsMessage (WindToCalc : WindowPtr);
  146.             VAR
  147.                 tempRect : Rect;
  148.                 aWindowPeek : WindowPeek;
  149.                 aRgn : RgnHandle;
  150.                 WindowRec : WindowPeek;
  151.         BEGIN
  152.             tempRect := WindToCalc^.PortRect;
  153.  
  154.             OffsetRect(tempRect, -WindToCalc^.PortBits.Bounds.Left, -WindToCalc^.PortBits.Bounds.Top);
  155.  
  156.             TempRect.top := TempRect.top - 1;
  157.             WindowRec := WindowPeek(WindToCalc);
  158.             RectRgn(WindowRec^.contRgn, tempRect);
  159.  
  160.             InsetRect(tempRect, -1, -1);
  161.             tempRect.top := tempRect.top - 12;
  162.             RectRgn(WindowRec^.strucRgn, tempRect);
  163.         END;
  164.  
  165.     BEGIN
  166.         MyWindowDef := 0;
  167.         CASE message OF
  168.             wDraw : 
  169.                 DoDrawMessage(theWindow, param);
  170.             wHit : 
  171.                 MyWindowDef := DoHitMessage(theWindow, param);
  172.             wCalcRgns : 
  173.                 DoCalcRgnsMessage(theWindow);
  174.             wNew : 
  175.                 ;
  176.             wDispose : 
  177.                 ;
  178.             wGrow : 
  179.                 ;
  180.         END;
  181.     END;
  182.  
  183. {        function GetItemRect(item : integer) : rect;               }
  184.  
  185.     FUNCTION GetItemRect (item : integer) : rect;
  186.         VAR
  187.             tempRect : Rect;
  188.     BEGIN
  189.         WITH tempRect DO
  190.             BEGIN
  191.                 top := (((item - 1) DIV 8) * 16) - 1;
  192.                 bottom := top + 17;
  193.                 left := (((item - 1) MOD 8) * 16) - 1;
  194.                 right := left + 17;
  195.             END;
  196.         GetItemRect := tempRect;
  197.     END;
  198.  
  199. {#            procedure DrawPatWindow;                          #}
  200.  
  201.     PROCEDURE DrawPatWindow;
  202.         VAR
  203.             i : integer;
  204.             currentPat : Pattern;
  205.             currRect : Rect;
  206.     BEGIN
  207.         FOR i := 1 TO 96 DO
  208.             BEGIN
  209.                 currRect := GetItemRect(i);
  210.                 FrameRect(currRect);
  211.                 GetIndPattern(currentPat, 100, i);
  212.                 FillRect(currRect, currentPat);
  213.                 FrameRect(currRect);
  214.             END;
  215.     END;
  216.  
  217. {#    function GetMItemRect(whichRect : Integer; myRect : Rect) : Rect;      #}
  218.  
  219.     FUNCTION GetMItemRect (whichRect : Integer;
  220.                                     myRect : Rect) : Rect;
  221.         VAR
  222.             ItemRect : Rect;
  223.     BEGIN
  224.         ItemRect := GetItemRect(whichRect);
  225.         OffSetRect(itemRect, myRect.left, myRect.top);
  226.         GetMItemRect := ItemRect;
  227.     END;
  228.  
  229. {#         procedure drawItem(myRect : rect; myItem : integer);           #}
  230.  
  231.     PROCEDURE drawItem (myRect : rect;
  232.                                     myItem : integer);
  233.         VAR
  234.             currentPat : pattern;
  235.     BEGIN
  236.         IF (myItem > 0) AND (myItem < 97) THEN
  237.             BEGIN
  238.                 myRect := GetMItemRect(myItem, myRect);
  239.                 GetIndPattern(currentPat, 100, myItem);
  240.                 FillRect(myRect, currentPat);
  241.                 FrameRect(myRect);
  242.             END;
  243.     END;
  244.  
  245. {#        procedure clearitem(myRect : Rect; lastCell : integer);           #}
  246.  
  247.     PROCEDURE clearitem (myRect : Rect;
  248.                                     lastCell : integer);
  249.     BEGIN
  250.         DrawItem(myRect, lastCell - 9);
  251.         DrawItem(myRect, lastCell - 8);
  252.         DrawItem(myRect, lastCell - 7);
  253.         DrawItem(myRect, lastCell - 1);
  254.         DrawItem(myRect, lastCell);
  255.         DrawItem(myRect, lastCell + 1);
  256.         DrawItem(myRect, lastCell + 7);
  257.         DrawItem(myRect, lastCell + 8);
  258.         DrawItem(myRect, lastCell + 9);
  259.     END;
  260.  
  261. {#            Menu Definition Routine                       #}
  262.  
  263.     PROCEDURE MyMenuDef (message : Integer;
  264.                                     theMenu : MenuHandle;
  265.                                     VAR menuRect : Rect;
  266.                                     hitPt : Point;
  267.                                     VAR whichItem : Integer);
  268.  
  269.         PROCEDURE DoDrawMessage (myMenu : MenuHandle;
  270.                                         myRect : Rect);
  271.             CONST
  272.                 MBarHeight = 20;
  273.             VAR
  274.                 whichRect : Integer;
  275.                 currentPat : Pattern;
  276.                 currRect : Rect;
  277.         BEGIN
  278.             FOR whichRect := 1 TO 96 DO
  279.                 Drawitem(myRect, whichRect);
  280.         END;
  281.  
  282.         FUNCTION DoChooseMessage (myMenu : MenuHandle;
  283.                                         myRect : Rect;
  284.                                         myPoint : Point;
  285.                                         oldItem : Integer) : Integer;
  286.             VAR
  287.                 currRect : Rect;
  288.                 alldone : boolean;
  289.                 whichRect : Integer;
  290.                 oldRect : Rect;
  291.                 mPt : Point;
  292.                 lastPt : Point;
  293.                 lastRect : Rect;
  294.                 menuPt : Point;
  295.                 tempRect : Rect;
  296.                 exitrect : rect;
  297.                 saveClip : RgnHandle;
  298.                 io : integer;
  299.         BEGIN
  300.             ClipRect(myRect);
  301.             whichRect := 1;
  302.             alldone := false;
  303.             REPEAT
  304.                 currRect := GetMItemRect(whichRect, myRect);
  305.                 IF PtInRect(myPoint, currRect) THEN
  306.                     alldone := true
  307.                 ELSE
  308.                     whichRect := whichRect + 1;
  309.             UNTIL ((AllDone) OR (whichRect > 96));
  310.             IF AllDone THEN { if we are in a item}
  311.                 BEGIN
  312.                     IF (whichRect <> oldItem) THEN
  313.                         BEGIN
  314.                             IF (oldItem <> 0) THEN
  315.                                 ClearItem(myRect, oldItem);
  316.                             InsetRect(currRect, -6, -6);
  317.                             PenSize(6, 6);
  318.                             PenPat(white);
  319.                             FrameRect(currRect);
  320.                             PenNormal;
  321.                             InsetRect(currRect, -1, -1);
  322.                             FrameRect(currRect);
  323.                         END;
  324.                     DoChooseMessage := whichRect;
  325.                 END
  326.             ELSE { we are not in a item}
  327.                 BEGIN
  328.                     IF oldItem <> 0 THEN { invert the old item}
  329.                         clearitem(myRect, oldItem);
  330.                     DoChooseMessage := 0;
  331.  
  332.                     PenMode(notPatXOR);
  333.                     penpat(gray);
  334.                     exitrect := myrect;
  335.                     InsetRect(ExitRect, -10, -10);
  336.                     ExitRect.top := 20;
  337.                     menuPt.h := myRect.left + ((myRect.right - myRect.left) DIV 2);
  338.                     menuPt.v := myRect.top + ((myRect.bottom - myRect.top) DIV 2);
  339.                     SetRect(tempRect, 0, 0, 0, 0);
  340.                     lastRect := tempRect;
  341.                     ClipRect(screenbits.bounds);
  342.                     REPEAT
  343.                         GetMouse(mPt);
  344.                         LocalToGlobal(mPt);
  345.                         IF ((Longint(mpt) <> Longint(lastPt)) AND (NOT PtInRect(mpt, ExitRect)) AND (mPt.v > 20)) THEN
  346.                             BEGIN
  347.                                 lastPt := mPt;
  348.                                 tempRect := myRect;
  349.                                 OffSetRect(tempRect, mPt.h - menuPt.h, mPt.v - menuPt.v);
  350.                                 IF tempRect.top < 20 THEN
  351.                                     BEGIN
  352.                                         tempRect.top := 20;
  353.                                         tempRect.bottom := 20 + 202;
  354.                                     END;
  355.                                 FrameRect(lastRect);
  356.                                 FrameRect(tempRect);
  357.                                 lastRect := tempRect;
  358.                             END;
  359.                     UNTIL (NOT button) OR ptInRect(mPt, exitrect) OR (mPt.v < 21);
  360.                     FrameRect(lastRect);
  361.                     PenNormal;
  362.                     IF (NOT PtInRect(mpt, ExitRect)) AND (mPt.v > 20) THEN
  363.                         BEGIN
  364.                             lastrect.top := lastrect.top + 12;
  365.                             io := PostEvent(12, Longint(lastRect.topleft));
  366.           { this communicates back to the main event}
  367.           { loop that a window was just torn from the}
  368.           { menu.  We pass the new topLeft in the message}
  369.                         END;
  370.                 END;
  371.         END;
  372.  
  373.         PROCEDURE DoSizeMessage (VAR myMenu : MenuHandle);
  374.         BEGIN
  375.             WITH myMenu^^ DO
  376.                 BEGIN
  377.                     menuWidth := 127;
  378.                     menuHeight := 191;
  379.                 END;
  380.         END;
  381.  
  382.     BEGIN
  383.         CASE message OF
  384.             mSizeMsg : 
  385.                 DoSizeMessage(theMenu);
  386.             mDrawMsg : 
  387.                 DoDrawMessage(theMenu, menuRect);
  388.             mChooseMsg : 
  389.                 whichItem := DoChooseMessage(theMenu, menuRect, hitPt, whichItem);
  390.         END;
  391.     END;
  392.  
  393. {#                 ShowAbout procedure                   #}
  394.  
  395.     PROCEDURE ShowAbout;
  396.         VAR
  397.             theDlog : DialogPtr;
  398.             theItem : Integer;
  399.     BEGIN
  400.         theDlog := GetNewDialog(AboutID, NIL, Pointer(-1));
  401.         ModalDialog(NIL, theItem);
  402.         DisposDialog(theDlog);
  403.     END;
  404.  
  405. {#                ProcessMenu procedure                   #}
  406.  
  407.     PROCEDURE ProcessMenu (codeWord : Longint);
  408.         TYPE
  409.             PatPtr = ^Pattern;
  410.         VAR
  411.             menuNum : Integer;
  412.             itemNum : Integer;
  413.             NameHolder : str255;
  414.             dummy : Integer;
  415.             yuck : boolean;
  416.             myPattern : Pattern;
  417.             DeskPatternPtr : PatPtr;
  418.             savePort, aPort : grafPtr;
  419.             theRgn1, theRgn2 : RgnHandle;
  420.     BEGIN
  421.         IF codeWord <> 0 THEN
  422.             BEGIN
  423.                 menuNum := HiWord(codeWord);
  424.                 itemNum := LoWord(codeWord);
  425.                 CASE menuNum OF { the different menus}
  426.                     AppleMenuID : 
  427.                         IF itemNum < 3 THEN
  428.                             ShowAbout
  429.                         ELSE
  430.                             BEGIN
  431.                                 GetItem(myMenus[AppleMenuID], itemNum, NameHolder);
  432.                                 dummy := OpenDeskAcc(NameHolder);
  433.                             END;
  434.                     FileMenuID : 
  435.                         Done := true;
  436.                     EditMenuID : 
  437.                         yuck := SystemEdit(itemNum - 1);
  438.                     GraphicalMenu : 
  439.                         IF ItemNum <> 0 THEN
  440.                             BEGIN
  441.                                 GetIndPattern(myPattern, 100, ItemNum);
  442.                                 SetPort(currentPatWind);
  443.                                 BackPat(myPattern);
  444.                                 EraseRect(currentPatWind^.portRect);
  445.                             END;
  446.                 END;
  447.                 HiliteMenu(0);
  448.             END;
  449.     END;
  450.  
  451. {#            Deal With Mouse Downs procedure                   #}
  452.  
  453.     PROCEDURE DealWithMouseDowns (theEvent : EventRecord);
  454.         VAR
  455.             location : Integer;
  456.             windowPointedTo : WindowPtr;
  457.             mouseLoc : point;
  458.             windowLoc : integer;
  459.             VandH : Longint;
  460.             Height : Integer;
  461.             Width : Integer;
  462.             currRect, myRect : Rect;
  463.             newcell, LastCell : integer;
  464.             thePt, LastPt : Point;
  465.             i : integer;
  466.             myPattern : Pattern;
  467.     BEGIN
  468.         mouseLoc := theEvent.where;
  469.         windowLoc := FindWindow(mouseLoc, windowPointedTo);
  470.         CASE windowLoc OF
  471.             inMenuBar : 
  472.                 ProcessMenu(MenuSelect(mouseLoc));
  473.             inSysWindow : 
  474.                 SystemClick(theEvent, windowPointedTo);
  475.             inContent : 
  476.                 IF windowPointedTo <> FrontWindow THEN
  477.                     SelectWindow(windowPointedTo)
  478.                 ELSE
  479.                     BEGIN
  480.                         IF RegWDEFWindow = windowPointedTo THEN
  481.                             BEGIN
  482.                                 SetPort(RegWDEFWindow);
  483.                                 GetMouse(lastPt);
  484.                                 newCell := 0;
  485.                                 lastCell := 0;
  486.                                 myRect := RegWDEFWindow^.portRect;
  487.                                 WHILE waitmouseup DO {track mouse in pattern wind}
  488.                                     BEGIN
  489.                                         GetMouse(thePt);
  490.                                         IF NOT PtInRect(thePt, myRect) THEN
  491.                                             BEGIN {we moved outside the window}
  492.                                                 IF lastCell <> 0 THEN
  493.                                                     clearItem(myRect, lastCell);
  494.                                                 lastCell := 0;
  495.                                             END
  496.                                         ELSE
  497.                                             BEGIN
  498.                                                 FOR i := 1 TO 96 DO
  499.                                                     IF PtInRect(thePt, GetItemRect(i)) THEN
  500.                                                         newCell := i;
  501.                                                 IF newCell <> lastCell THEN
  502.                                                     BEGIN
  503.                                                         IF (lastCell <> 0) THEN
  504.                                                             Clearitem(myRect, lastCell);
  505.                                                         currRect := GetItemRect(newCell);
  506.                                                         InsetRect(currRect, -6, -6);
  507.                                                         PenSize(6, 6);
  508.                                                         PenPat(white);
  509.                                                         FrameRect(currRect);
  510.                                                         PenNormal;
  511.                                                         InsetRect(currRect, -1, -1);
  512.                                                         FrameRect(currRect);
  513.                                                         lastCell := newCell;
  514.                                                     END;
  515.                                             END;
  516.                                     END;
  517.                                 Clearitem(myRect, lastCell);
  518.                                 GetIndPattern(myPattern, 100, newCell);
  519.                                 SetPort(currentPatWind);
  520.                                 BackPat(myPattern);
  521.                                 EraseRect(currentPatWind^.portRect);
  522.                             END;
  523.                     END;
  524.             inDrag : 
  525.                 BEGIN
  526.                     DragWindow(windowPointedTo, mouseLoc, DragArea);
  527.                     SelectWindow(windowPointedTo);
  528.                 END;
  529.             inGoAway : 
  530.                 IF TrackGoAway(windowPointedTo, mouseLoc) THEN
  531.                     HideWindow(windowPointedTo);
  532.         END;
  533.     END;
  534.  
  535. {#            Deal With Key Downs procedure                   #}
  536.  
  537.     PROCEDURE DealWithKeyDowns (theEvent : EventRecord);
  538.         TYPE
  539.             Trick = PACKED RECORD
  540.                     CASE boolean OF
  541.                         true : (
  542.                                 long : Longint
  543.                         );
  544.                         false : (
  545.                                 chr3, chr2, chr1, chr0 : char
  546.                         )
  547.                 END;
  548.         VAR
  549.             CharCode : char;
  550.             TrickVar : Trick;
  551.     BEGIN
  552.         TrickVar.long := theEvent.message;
  553.         CharCode := TrickVar.chr0;
  554.         IF BitAnd(theEvent.modifiers, CmdKey) = CmdKey THEN {check for a menu selection}
  555.             ProcessMenu(MenuKey(CharCode))
  556.     END;
  557.  
  558. {#            Deal With Updates procedure                   #}
  559.  
  560.     PROCEDURE DealWithUpdates (theEvent : EventRecord);
  561.         VAR
  562.             UpDateWindow : WindowPtr;
  563.             tempPort : WindowPtr;
  564.  
  565.     BEGIN
  566.         UpDateWindow := WindowPtr(theEvent.message);
  567.         GetPort(tempPort);
  568.         SetPort(UpDateWindow);
  569.         BeginUpDate(UpDateWindow);
  570.         EraseRect(UpDateWindow^.portRect);
  571.         IF UpdateWindow <> currentPatWind THEN
  572.             DrawPatWindow;
  573.         EndUpDate(UpDateWindow);
  574.         SetPort(tempPort);
  575.     END;
  576.  
  577. {#            MainEventLoop procedure                       #}
  578.  
  579.     PROCEDURE MainEventLoop;
  580.         VAR
  581.             Event : EventRecord;
  582.             ProcessIt : boolean;
  583.             where : Point;
  584.     BEGIN
  585.         REPEAT
  586.             SystemTask;
  587.             IF GetNextEvent(everyEvent, Event) THEN
  588.                 CASE Event.what OF
  589.                     mouseDown : 
  590.                         DealWithMouseDowns(Event);
  591.                     AutoKey : 
  592.                         DealWithKeyDowns(Event);
  593.                     KeyDown : 
  594.                         DealWithKeyDowns(Event);
  595.                     UpdateEvt : 
  596.                         DealWithUpdates(Event);
  597.                     12 : 
  598.                         BEGIN { we return this when a window has been torn}
  599.                             where := Point(Event.message);
  600.                             HideWindow(RegWDefWindow);
  601.                             MoveWindow(RegWDefWindow, where.h, where.v, true);
  602.                             ShowWindow(RegWDEFWindow);
  603.                         END;
  604.                     OTHERWISE
  605.                         BEGIN
  606.                         END;
  607.                 END; {of case}
  608.         UNTIL Done;
  609.     END;
  610.  
  611. {#                 SetupMemory procedure                   #}
  612.  
  613.     PROCEDURE SetupMemory;
  614.         VAR
  615.             x : Longint;
  616.     BEGIN
  617. {x := ORD4(ApplicZone) + 128000;}
  618. {SetApplLimit(Pointer(x));}
  619.         MaxApplZone;
  620.         MoreMasters;
  621.         MoreMasters;
  622.         MoreMasters;
  623.     END;
  624.  
  625. {#                 SetupLimits                       #}
  626.  
  627.     PROCEDURE SetupLimits;
  628.         VAR
  629.             Screen : Rect;
  630.     BEGIN
  631.         Screen := ScreenBits.bounds;
  632.         WITH Screen DO
  633.             BEGIN
  634.                 SetRect(DragArea, left + 4, top + 24, right - 4, bottom - 4);
  635.                 SetRect(GrowArea, left, top + 24, right, bottom);
  636.             END;
  637.     END;
  638.  
  639. {#                MakeMenus procedure                   #}
  640.  
  641.     PROCEDURE MakeMenus;
  642.         VAR
  643.             index : Integer;
  644.     BEGIN
  645.         FOR index := AppleMenuID TO EditMenuID DO
  646.             BEGIN
  647.                 myMenus[index] := GetMenu(index);
  648.                 InsertMenu(myMenus[index], 0);
  649.             END;
  650.         AddResMenu(myMenus[AppleMenuID], 'DRVR');
  651.  
  652.         MyGraphicsMenu := NewMenu(4, 'Graphics');
  653.  
  654.         MyGraphicsMenu^^.menuProc := NewHandle(0);
  655.         MyGraphicsMenu^^.menuProc^ := Ptr(@MyMenuDef);
  656.         CalcMenuSize(MyGraphicsMenu);
  657.  
  658.         Insertmenu(MyGraphicsMenu, 0);
  659.  
  660.         DrawMenuBar;
  661.     END;
  662.  
  663.     PROCEDURE crash;
  664.     BEGIN
  665.         ExitToShell;
  666.     END;
  667.  
  668. {#            Program Excecution Starts Here                   #}
  669.  
  670. BEGIN
  671.     InitGraf(@thePort);
  672.     InitFonts;
  673.     InitWindows;
  674.     InitMenus;
  675.     TEInit;
  676.     InitDialogs(@crash);
  677.     InitCursor;
  678.     Done := false;
  679.     FlushEvents(everyEvent, 0);
  680.  
  681.     SetupLimits;
  682.     SetupMemory;
  683.     MakeMenus;
  684.  
  685.     RegWDEFWindow := GetNewWindow(WindResID, NIL, Pointer(-1));
  686.     myWindowPeek := WindowPeek(RegWDEFWindow);
  687.  
  688.     myWindowPeek^.windowDefProc := NewHandle(0);
  689.     myWindowPeek^.windowDefProc^ := Ptr(@MyWindowDef);
  690.  
  691.     SetWRefCon(RegWDEFWIndow, Ord4(MyGraphicsMenu));
  692.  
  693.     currentPatWind := GetNewWindow(2, NIL, pointer(-1));
  694.     SetPort(currentPatWind);
  695.     BackPat(gray);
  696.     EraseRect(currentPatWind^.portRect);
  697.  
  698.     MainEventLoop;
  699. END. {thats all folkes!}